﻿using System;
using System.Data;
using System.Windows.Forms;


namespace wap主题
{
    [Serializable]
    public class 主题Data
    {

        public const string PER_Field = @"per";

        public const string UA_Field = @"ua";

        public const string WAP链接地址_Field = @"wap链接地址";

        public const string 版权归属及分成模式_Field = @"版权归属及分成模式";

        public const string 简单说明_Field = @"简单说明";

        public const string 名称_Field = @"名称";

        public const string 推荐指数_Field = @"推荐指数";

        public const string 资费_Field = @"资费";

        public const string 作品名_Field = @"作品名";

        private Single _per;

        private String _ua;

        private String _wap链接地址;

        private String _版权归属及分成模式;

        private String _简单说明;

        private String _名称;

        private String _推荐指数;

        private String _资费;

        private String _作品名;

        public Single per
        {
            get { return _per; }
            set { _per = value; }
        }
        public String ua
        {
            get { return _ua; }
            set { _ua = value; }
        }
        public String wap链接地址
        {
            get { return _wap链接地址; }
            set { _wap链接地址 = value; }
        }
        public String 版权归属及分成模式
        {
            get { return _版权归属及分成模式; }
            set { _版权归属及分成模式 = value; }
        }
        public String 简单说明
        {
            get { return _简单说明; }
            set { _简单说明 = value; }
        }
        public String 名称
        {
            get { return _名称; }
            set { _名称 = value; }
        }
        public String 推荐指数
        {
            get { return _推荐指数; }
            set { _推荐指数 = value; }
        }
        public String 资费
        {
            get { return _资费; }
            set { _资费 = value; }
        }
        public String 作品名
        {
            get { return _作品名; }
            set { _作品名 = value; }
        }
        public 主题Data()
        {
            _per = 0;
            _ua = "";
            _wap链接地址 = "";
            _版权归属及分成模式 = "";
            _简单说明 = "";
            _名称 = "";
            _推荐指数 = "";
            _资费 = "";
            _作品名 = "";
        }
    }

    public class 主题DataFactory
    {
        public static 主题Data Construct(IDataReader reader)
        {
            主题Data data = new 主题Data();

            data.per = Convert.ToSingle(reader["per"]);

            data.ua = Convert.ToString(reader["ua"]);

            data.wap链接地址 = Convert.ToString(reader["wap链接地址"]);

            data.版权归属及分成模式 = Convert.ToString(reader["版权归属及分成模式"]);

            data.简单说明 = Convert.ToString(reader["简单说明"]);

            data.名称 = Convert.ToString(reader["名称"]);

            data.推荐指数 = Convert.ToString(reader["推荐指数"]);

            data.资费 = Convert.ToString(reader["资费"]);

            data.作品名 = Convert.ToString(reader["作品名"]);

            return data;
        }      
        public static 主题Data Construct(DataTable dt)
        {
            return Construct(dt, 0);
        }
        public static 主题Data Construct(DataTable dt, int rowIndex)
        {
            主题Data data = new 主题Data();

            if (dt.Rows.Count < rowIndex + 1)

                return null;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return null;

            try { data.per = Convert.ToSingle(dr["per"]); }
            catch { }

            try { data.ua = Convert.ToString(dr["ua"]); }
            catch { }

            try { data.wap链接地址 = Convert.ToString(dr["wap链接地址"]); }
            catch { }

            try { data.版权归属及分成模式 = Convert.ToString(dr["版权归属及分成模式"]); }
            catch { }

            try { data.简单说明 = Convert.ToString(dr["简单说明"]); }
            catch { }

            try { data.名称 = Convert.ToString(dr["名称"]); }
            catch { }

            try { data.推荐指数 = Convert.ToString(dr["推荐指数"]); }
            catch { }

            try { data.资费 = Convert.ToString(dr["资费"]); }
            catch { }

            try { data.作品名 = Convert.ToString(dr["作品名"]); }
            catch { }

            return data;
        }
        public static 主题Data Construct(DataGridView dgv, int rowIndex)
        {
            主题Data data = new 主题Data();

            if (dgv.Rows.Count < rowIndex + 1)

                return null;

            DataGridViewCellCollection dr = dgv.Rows[rowIndex].Cells;

            if (dr == null)

                return null;

            for (int i = 0; i < dgv.Columns.Count; i++)
            {
                switch (dgv.Columns[i].DataPropertyName)
                {
                    case "per":
                        try { data.per = Convert.ToSingle(dr[i].Value); }
                        catch { }
                        break;
                    case "ua":
                        try { data.ua = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "wap链接地址":
                        try { data.wap链接地址 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "版权归属及分成模式":
                        try { data.版权归属及分成模式 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "简单说明":
                        try { data.简单说明 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "名称":
                        try { data.名称 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "推荐指数":
                        try { data.推荐指数 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "资费":
                        try { data.资费 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                    case "作品名":
                        try { data.作品名 = Convert.ToString(dr[i].Value); }
                        catch { }
                        break;
                }
            }
            return data;
        }        
    }
}